/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pagoda.util.xml;

import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

/**
 *
 * @author Kevin Krohe
 */
public class XmlUtil {

    public static String getAttrValue(Node node, String name, String defaultVal)
    {
        NamedNodeMap attrs = node.getAttributes();
        Node attr = attrs.getNamedItem(name);
        if(attr == null)
            return defaultVal;
        if(attr instanceof Attr)
        {
            return ((Attr)attr).getValue();
        }
        return node.getNodeValue();
    }

    public static String getAttrValue(Node node, String name)
    {
        NamedNodeMap attrs = node.getAttributes();
        Node attr = attrs.getNamedItem(name);
        if(attr == null)
            return null;
        if(attr instanceof Attr)
        {
            return ((Attr)attr).getValue();
        }
        return node.getNodeValue();
    }

}
